package com.dxy.shardingjdbc.controller;



import com.dxy.shardingjdbc.model.po.Product;
import com.dxy.shardingjdbc.model.po.ProductDetail;
import com.dxy.shardingjdbc.model.po.ProductInfo;
import com.dxy.shardingjdbc.service.ProductDetailService;
import com.dxy.shardingjdbc.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品表(Product)表控制层
 *
 * @author dangxianyue
 * @since 2023-02-11 13:30:40
 */
@Api(tags = "商品接口")
@RestController
@RequestMapping("product")
public class ProductController {

    @Resource
    private ProductService productService;
    @Resource
    private ProductDetailService productDetailService;

    @ApiOperation("新增商品")
    @PostMapping("/saveProduct")
    public Product saveProduct(String productName) {
        Product product = new Product().setProductName(productName);
        productService.save(product);
        return product;
    }

    @ApiOperation("新增商品详情")
    @PostMapping("/saveProductDetail")
    public ProductDetail saveProductDetail(Long productId, String productDetail) {
        ProductDetail productDetail1 = new ProductDetail().setProductId(productId).setProductDetail(productDetail);
        productDetailService.save(productDetail1);
        return productDetail1;
    }

    @ApiOperation("查询商品列表")
    @GetMapping("/findProductList")
    public List<ProductInfo> findProductList(String productName) {
        return productService.findProductList(productName);
    }

}

